package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.viewmodel.entity.EntityChartValue;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * CREATE BY zlzxm ON 4/25/21
 */
public class VMTendency extends ViewModel {


    private MutableLiveData<List<EntityChartValue>> liveData = new MutableLiveData<>();

    public MutableLiveData<List<EntityChartValue>> getLiveData() {
        return liveData;
    }



    public void getData(){

        Observable.timer(1, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveData.setValue(createTestPriceData());
                    }
                });




    }


    private List<EntityChartValue> createTestPriceData(){


        List<EntityChartValue> list = new ArrayList<>();


        list.add(new EntityChartValue("2019-01",749));
        list.add(new EntityChartValue("2019-02",45));
        list.add(new EntityChartValue("2019-03",890));
        list.add(new EntityChartValue("2019-04",89));
        list.add(new EntityChartValue("2019-05",480));
        list.add(new EntityChartValue("2019-06",300));


        return  list;

    }

}
